﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;

namespace ESoft.Logging
{
    /// <summary>
    /// Nlog扩展
    /// </summary>
    public static class NLogExtentions
    {
        /// <summary>
        /// 设置nlog注入
        /// </summary>
        /// <param name="services"></param>
        public static void AddNLoging(this IServiceCollection services)
        {
            services.AddSingleton(typeof(ILogging<>), typeof(Logging<>));
        }

        /// <summary>
        /// 使用nlog
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configPath"></param>
        public static void UseNLog(this IServiceProvider serviceProvider,string configPath)
        {
            LogManager.LoadConfiguration(configPath);
            var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
            loggerFactory.AddNLog();
        }
    }
}
